package com.lanou3g.Hw0516.util;



import org.junit.Test;

import java.util.UUID;

public class TestUUID {
    //UUID一个字符串
    @Test
    public void fun(){
        String uuid = UUID.randomUUID().toString();
        System.out.println(uuid);

    }
    public static String getRandomString(){
        String uuid = UUID.randomUUID()
                .toString()//转换成字符串
                .replace("-","")//去掉短线
                .toUpperCase();//转成大写字母
        return uuid;
    }
    //aaa.png=>uuid.png
    public static String handleFileName(String fileName){
        String name= getRandomString();//获取uuid
        int lastIndex=fileName.lastIndexOf(".");
        String expand = fileName.substring(lastIndex,fileName.length());
        return name+expand;//拼接成新的文件名
    }
    @Test
    public void test01(){
        String newName = handleFileName("aaa.png");
        System.out.println(newName);
    }
}
